<?php
require_once('includes/Init.php');
ini_set('error_log', 'logs/php_log');
//phpinfo();
session_start();
error_log("\n");
error_log("load index\n");

$action = 'start';

if('login' == $_REQUEST['action']) {
    error_log("session not locked in\n");
    $login = new Login();
    $action = $login->action();
//    }
} elseif ('register' == $_REQUEST['action']) {
    $register = new Register();
    $action = $register->action();
} else {
    if (isset($_REQUEST['ajax'])) {
        $action = 'ajax';
        error_log("\n in index ajax {$_REQUEST['ajax']}\n");
        $ajaxManager = Ajax_Manager::getInstance();
        $ajaxData = $ajaxManager->delegate($_REQUEST['ajax'])
            ->fetch()->returnAjax()
        ;
        echo $ajaxData;
//        require_once(getDocumentRoot() . 'templates/' . $_REQUEST['ajax']);
    } else {
        if(isset($_REQUEST['action'])) {
            $action = $_REQUEST['action'];
        }
//        require_once(getDocumentRoot() . 'actions/action_' . $action . '.es');
    }
}
if (!isset($_REQUEST['ajax'])) {
    $user = new User();
    $user->isLoggedIn();
    require_once(getDocumentRoot() . 'actions/action_' . $action . '.es');
}

